<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>随手快递</title>
    <link rel="stylesheet" href="../../bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="../../bootstrap/css/bootstrap-select.css">
    <link rel="stylesheet" type="text/css" href="../../AUI/css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../font-awesome/css/font-awesome.min.css" />
    <link rel="stylesheet" href="../../myCss/LArea.css">
    <style type="text/css">
        img.avatar {
            display: block;
            margin: 0 auto;
            width: 20%;
        }
        .aui-radio{
            width: 20px;
            height: 20px;
        }
        .aui-radio:checked {
            background: #EE6E73;
            border: 1px solid #EE6E73;
            width: 20px;
            height: 20px;
        }
    </style>
</head>
<body style="font-family: 微软雅黑;">
<header class="aui-bar aui-bar-nav" id="aui-header">
    <a class="aui-btn aui-pull-left" tapmode onclick="history.back();">
        <span class="aui-iconfont aui-icon-left"></span>
    </a>
    <div class="aui-title">编辑个人资料</div>
    <div class="aui-btn aui-pull-right" onclick="submit()"><span class="fa fa-check-square-o fa-lg"></span></div>
</header>
<div class="aui-content"style="margin-top: 45px" >
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item aui-list-item-middle aui-border-b">
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-inner">
                        头像
                    </div>
                    <div class="aui-list-item-media" id="head_btn" style="margin-left: 40px">
                        <img id="headPortraitUrl" class="aui-img-round aui-list-img-sm">
                    </div>
                    <div style="display:none">
                        <p><input type="file" id="head_file_ipt" name="file" multiple onChange="ajaxFileUpload();"  /></p>
                        <input type="button" value="上传" />
                    </div>


                </div>
            </li>
            <li class="aui-list-item aui-border-b">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="font-size: 15px">
                        昵称
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" id="nickname"  style="font-size: 15px">
                    </div>
                </div>
            </li>
            <li class="aui-list-item aui-border-b">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label"  style="font-size: 15px">
                        性别
                    </div>
                    <div class="aui-list-item-input">
                        <label style="font-size: 15px"><input class="aui-radio" type="radio" name="sex" value="男"> 男 </label>&nbsp;&nbsp;
                        <label style="font-size: 15px"><input class="aui-radio" type="radio" name="sex" value="女"> 女</label>
                    </div>
                </div>
            </li>
            <li class="aui-list-item aui-border-b">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label"  style="font-size: 15px">
                        地区
                    </div>
                    <div class="aui-list-item-input">
                        <div class="content-block">
                            <input id="address" type="text" readonly  />
                            <input id="value2" type="hidden" />
                        </div>
                    </div>
                </div>
            </li>
            <li class="aui-list-item aui-border-b">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label"  style="font-size: 15px">
                        个性签名
                    </div>
                    <div class="aui-list-item-input">
                        <textarea style="font-size: 15px" id="signature"></textarea>
                    </div>
                </div>
            </li>
            </ul>
        </div>
</div>
</body>
<script type="text/javascript" src="../../AUI/script/api.js" ></script>
<script src="../../myJs/jquery-1.12.1.min.js"></script>
<script src="../../myJs/jquery.cookie.js"></script>
<script src="../../myJs/ajaxfileupload.js"></script>
<script src="../../myJs/LAreaData1.js"></script>
<script src="../../myJs/LAreaData2.js"></script>
<script src="../../myJs/LArea.js"></script>


<script type="text/javascript">
    apiready = function () {
    }
    var area2 = new LArea();
    area2.init({
        'trigger': '#address',
        'valueTo': '#value2',
        'keys': {
            id: 'value',
            name: 'text'
        },
        'type': 2,
        'data': [provs_data, citys_data, dists_data]
    });
 /*    var data={
        "code":200,
        "user":{
            "userId": "33",
            "nickname": "嘿嘿",
            "userCredit": "98",
            "integral": "99",
            "region": "浙江省杭州市江干区",
            "signature": "这个人很懒",
            "headPortraitUrl": "../../myImage/6.jpg",
            "sex": "男"
        }
    } */
    $(function(){
       
         $.ajax({
         type: "post",
         url: '/randomdelivery/userManageController/infomation',
         data: {},
         datatype: "json",
         success: function (data) {
        	 //alert(JSON.stringify(data));
        	 editInfo(data);
         }

         });
       
    })

    function editInfo(data){
        var data = data.msg;
        $("#nickname").val(data.nickname);
        $("#headPortraitUrl").attr("src",data.headPortraitUrl);
        if(data.sex=="女"){
            $("input[name='sex']:eq(1)").attr('checked','true');
        }else {
            $("input[name='sex']:eq(0)").attr('checked','true');
        }
        $("#address").val(data.region);
        $("#signature").val(data.signature);
    }

    function submit(){
        var nickname = $("#nickname").val();
        var address = $("#address").val();
        var signature = $("#signature").val();
        var sex = $('input[name="sex"]:checked').val();
        //alert(sex);
         $.ajax({
         type: "post",
         url: '/randomdelivery/userManageController/updateInfomation',
         data: {
         nickname:nickname,
         region:address,
         signature:signature,
         sex:sex
         },
         datatype: "json",
         success: function (data) {
        	
        	 location.href="viewInfo.html";
        	 
         }
         });
    }

    $("#head_btn").on("click",function(){
        $("#head_file_ipt").trigger("click");
    })
    /* 文件上传 */
    var userHeadUrl;
    function ajaxFileUpload() {
              $.ajaxFileUpload({
                  url : '/randomdelivery/userManageController/imageUpload', //用于文件上传的服务器端请求地址
                  secureuri : false, //是否需要安全协议，一般设置为false
                  fileElementId : 'head_file_ipt', //文件上传域的ID
                  dataType : 'json', //返回值类型 一般设置为json
                  contentType:'x-www-form-urlencoded',
                  success : function(data) { //服务器成功响应处理函数
                     // alert(JSON.stringify(data));
                  $("#headPortraitUrl").attr("src",data.msg.headUrl);
                      
                  },
                  error : function(data, status, e) { //服务器响应失败处理函数
                     // alert(JSON.stringify(data));
                     //alert(status);
                     // alert(e);
                  }
              });
    }
</script>
</html>